<template>
  <div class="home-swiper">
    <swiper ref="mySwiper" :options="swiperOptions" v-if="sliderList.length !== 0">
      <swiper-slide v-for="item in sliderList" :key="item.id">
        <img :src="item.imgUrl" :alt="item.title">
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props: {
    sliderList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data () {
    return {
      swiperOptions: {
        pagination: {
          el: '.swiper-pagination'
        },
        loop:true,
        autoplay: {
          delay: 2000,
        }
      }
    }
  }
}
</script>

<style scoped>
  .home-swiper {
    width: 100%;
    height: 0;
    padding-bottom: 53%;
    background: #ccc;
    overflow: hidden;
    margin-bottom: .2rem;
  }
  .home-swiper img {
    width: 100%;
    height: 100%;
  }
  /* stylus中的穿透覆盖样式 */
  .home-swiper >>> .swiper-pagination-bullet-active {
    background: #fff;
  }
</style>
